<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Landmarks_model extends CI_Model {
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    public function getAll() {
        $query = $this->db->query("
            SELECT *, left(landmark_details, 190) AS det_less FROM tb_landmarks
            WHERE landmark_barangay_id_fk = " .
            $this->session->userdata('barangay_id') .
            " ORDER BY landmark_date_posted DESC
        ");
        return $query->result();
    }
    public function insertLandmarks() {
        $query = $this->db->query("
            INSERT INTO tb_landmarks
            VALUES(NULL, "
                .$this->session->userdata('barangay_id').", "
                .$this->session->userdata('user_id').", '"
                .$this->input->post('l_name')."', '"
                .$this->input->post('l_addr'). "', '"
                .$this->input->post('l_det')."', "
                ."NULL, SYSDATE())
        ");
        return $this->db->insert_id();
        //return $query;
    }
    public function getLandmarkId($e=0) {
        //$query = $this->db->getwhere('tb_landmarks', array('landmark_id_pk'=>$e));
        $query = $this->db->query("
            SELECT * FROM tb_landmarks
            WHERE landmark_id_pk="
            .$e." AND landmark_barangay_id_fk="
            .$this->session->userdata('barangay_id')
            ." LIMIT 1
        ");
        //return $query->result();
        return $query->row_array();
    }
    public function deleteLandmarks($e=0) {
        $query = $this->db->query("
            DELETE FROM tb_landmarks
            WHERE landmark_id_pk="
            .$e." AND landmark_barangay_id_fk="
            .$this->session->userdata('barangay_id')."
        ");
        return $query;
    }
    public function updateLandmarks() {
        $query = $this->db->query("
            UPDATE  tb_landmarks SET landmark_name =  '"
            .$this->input->post('l_name')."',
            landmark_address =  '"
            .$this->input->post('l_addr')."',
            landmark_details =  '"
            .$this->input->post('l_det')."'
            WHERE landmark_id_pk ="
            .$this->input->post('l_id')." LIMIT 1 ;
        ");
        return 'ok';
    }
}